package com.drojian.demo3.service.remote;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.drojian.demo.R;

public class RemoteServiceActivity extends AppCompatActivity {
    private Button bind_remote_service,user_remote_service,unbind_remote_service;
    private EditText edit_remote_service;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.part3_activity_remote_service);
        edit_remote_service = findViewById(R.id.edit_remote_service);
    }

    private ServiceConnection conn;
    public void BindRemoteService(View view) {
        Intent intent = new Intent(this, RemoteServiceActivity.class);
        intent.setAction("com.drojian.demo3.service.remote.MyRemoteService.action");
        if(conn == null){
            conn = new ServiceConnection() {
                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {

                }
            };
            bindService(intent,conn, Context.BIND_AUTO_CREATE);
            Toast.makeText(this,"绑定成功",Toast.LENGTH_SHORT).show();

        }else {
            Toast.makeText(this,"已经进行绑定",Toast.LENGTH_SHORT).show();
        }
    }

    public void invokeService(View view) {
    }

    public void unBindRemoteService(View view) {
        if(conn != null){
            unbindService(conn);
            conn = null;
            Toast.makeText(this,"解绑成功",Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(this,"未进行绑定",Toast.LENGTH_SHORT).show();

        }
    }
}